package com.violet.myorm.utils;

import com.violet.myorm.core.source.Reflect;
import com.violet.myorm.core.sql.DeleteSql;
import com.violet.myorm.core.sql.InsertSql;
import com.violet.myorm.core.sql.QuerySql;
import com.violet.myorm.core.sql.UpdateSql;

import java.lang.reflect.Field;
import java.util.List;

public class SqlUtils {
    public static QuerySql createSelect(Class<?> clazz, List<Field> fields) {
        List<String> fieldsNames = fields.stream().map(Reflect::getFieldName).toList();
        return new QuerySql(Reflect.getTableName(clazz), fieldsNames);
    }

    public static QuerySql createSelect(Class<?> clazz, String... fields) {
        return new QuerySql(Reflect.getTableName(clazz), List.of(fields));
    }

    public static UpdateSql createUpdate(Class<?> clazz, List<String> fields, List<String> where) {
        return new UpdateSql(Reflect.getTableName(clazz), fields, where);
    }

    public static DeleteSql createDelete(Class<?> clazz, List<String> where) {
        return new DeleteSql(Reflect.getTableName(clazz), where);
    }

    public static InsertSql createInsert(Class<?> clazz, List<String> fields) {
        return new InsertSql(Reflect.getTableName(clazz), fields);
    }
}
